package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteSmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 短信服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteSmsFallbackFactory implements FallbackFactory<RemoteSmsService> {
    
    private static final Logger log = LoggerFactory.getLogger(RemoteSmsFallbackFactory.class);

    @Override
    public RemoteSmsService create(Throwable throwable) {
        log.error("短信服务调用失败:{}", throwable.getMessage());
        return new RemoteSmsService() {
            
            @Override
            public R<String> sendVerificationCode(String phoneNumber) {
                return R.fail("短信服务暂时不可用，请稍后重试");
            }

            @Override
            public R<String> sendVerificationCode(String phoneNumber, String code) {
                return R.fail("短信服务暂时不可用，请稍后重试");
            }

            @Override
            public R<String> verifyCode(String phoneNumber, String code) {
                return R.fail("短信验证服务暂时不可用，请稍后重试");
            }

            @Override
            public R<String> getSmsStatus(String phoneNumber) {
                return R.fail("短信状态查询服务暂时不可用，请稍后重试");
            }
        };
    }
}